package pl.edu.agh.anomalyids.lerad.rule.util;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import pl.edu.agh.anomalyids.lerad.rule.Rule;

public class RuleWriter {
	
	private static final Logger logger = LoggerFactory.getLogger(RuleWriter.class);
	
	private List<Rule> rules;

	public RuleWriter(List<Rule> rules) {
		super();
		this.rules = rules;
	}

	public void write(String filePath) {
		ObjectOutputStream output = null;
		try {
			FileOutputStream fileOutput = new FileOutputStream(filePath);
			output = new ObjectOutputStream(fileOutput);
			output.writeObject(rules);
			output.flush();
		} catch (IOException e) {
			logger.error("Error during packets serialization: " + e);
		} finally {
			try {
				output.close();
			} catch (IOException e) {
				logger.error("Error closing output stream: " + e);
			}
		}
	}
}
